home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / MorphOS / Epic4_mos / share / epic / script / less-pipe < prev    next >
Encoding:
Text File  |  2002-10-28  |  1018 b   |  69 lines

  1. #
  2. # Open up a pipe and then page the output.
  3. # I wrote this in a race with Archon (hop, 1997)
  4. #
  5.  
  6. #
  7. # Usage: 
  8. #  $0  - name of the pipe
  9. #  $1- - stuff to run
  10. #
  11. alias less_pipe
  12. {
  13.     @ line = 0
  14.  
  15.     if ([$1])
  16.     {
  17.         ^on ^exec "$0 *" {
  18.             @ lessline[$line] = [$1-]
  19.             @ line++
  20.         }
  21.         ^on ^exec_error "$0 *" {
  22.             echo *** Error on exec: $*
  23.         }
  24.         ^on ^exec_exit "$0 *" {
  25.             on exec -"$0 *"
  26.             on exec_error -"$0 *"
  27.             on exec_exit -"$0 *"
  28.             less_array lessline 0 $line
  29.         }
  30.         exec -name $*
  31.     }
  32. }
  33.  
  34. /*
  35.  * $0 is the array name to use
  36.  * $1 is the starting line
  37.  * $2 is the final line
  38.  */
  39. alias less_array
  40. {
  41.     local line $1
  42.     local cr 0
  43.     local rows $winsize()
  44.  
  45.     while ((line < [$2]) && (cr < rows))
  46.     {
  47.         echo $($0[$line])
  48.         assign -$0[$line]
  49.         @ line++, cr++
  50.     }
  51.  
  52.     if (cr >= rows)
  53.     {
  54.         @ aaa.array_name = [$0]
  55.         @ aaa.next_line = line
  56.         @ aaa.final_line = [$2]
  57.  
  58.         input_char "Enter q to quit, or anything else to continue "
  59.         {
  60.             if ([$0] != [q])
  61.             {
  62.                 ^less_array $aaa.array_name $aaa.next_line $aaa.final_line
  63.             }
  64.         }
  65.     }
  66. }
  67.  
  68. #hop'97
  69.